﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace Project_V1
{
    public partial class FrmGraphs : Form
    {
        ToolTip tt = new ToolTip();
        public FrmGraphs()
        {
            InitializeComponent();
            this.Load += FrmGraphs_Load;
        }

        private void FrmGraphs_Load(object sender, EventArgs e)
        {
            #region 初始化chart
            //初始化chart
            this.chart1.Series.Clear();
            //this.chart1.ChartAreas.Clear();

            Series objSeries1 = chart1.Series.Add("压力");
            Series objSeries2 = chart1.Series.Add("扭矩");
            Series objSeries3 = chart1.Series.Add("进给速度");
            Series objSeries4 = chart1.Series.Add("旋转速度");
            Series objSeries5 = chart1.Series.Add("进给位移");

            Series seriesCopy1 = chart1.Series.Add("扭矩_Copy");//添加Series扭矩_Copy
            Series seriesCopy2 = chart1.Series.Add("进给速度_Copy");
            Series seriesCopy3 = chart1.Series.Add("旋转速度_Copy");
            Series seriesCopy4 = chart1.Series.Add("进给位移_Copy");

            //ChartArea chartArea = chart1.ChartAreas.Add("ChartArea1");
            ChartArea areaSeries1 = chart1.ChartAreas.Add("ChartArea2");
            ChartArea areaSeries2 = chart1.ChartAreas.Add("ChartArea4");
            ChartArea areaSeries3 = chart1.ChartAreas.Add("ChartArea6");
            ChartArea areaSeries4 = chart1.ChartAreas.Add("ChartArea8");

            ChartArea areaAxis1 = chart1.ChartAreas.Add("ChartArea3");
            ChartArea areaAxis2 = chart1.ChartAreas.Add("ChartArea5");
            ChartArea areaAxis3 = chart1.ChartAreas.Add("ChartArea7");
            ChartArea areaAxis4 = chart1.ChartAreas.Add("ChartArea9");



            chart1.ChartAreas["ChartArea1"].Position = new ElementPosition(20, 9, 74, 86);//X，Y，宽，高
            chart1.ChartAreas["ChartArea1"].InnerPlotPosition = new ElementPosition(6, 0, 94, 90);//不包括刻度线和轴标签



            chart1.Series["压力"].Color = Color.Black;
            chart1.ApplyPaletteColors();

            chart1.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 10, FontStyle.Regular);
            chart1.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
            chart1.ChartAreas[0].AxisX.TitleAlignment = StringAlignment.Center;
            chart1.ChartAreas[0].AxisX.Title = "进给位移(mm)";

            //chart1.ChartAreas[0].AxisX.Maximum = -38.1;
            //chart1.ChartAreas[0].AxisX.Minimum = -40.1;
            //chart1.ChartAreas[0].AxisX.Interval = 0.5;
            //chart1.ChartAreas[0].AxisX.IntervalOffset = 0.1;
            chart1.ChartAreas[0].AxisX.Minimum = 0;//
            chart1.ChartAreas[0].AxisX.Interval = 0.5;
            chart1.ChartAreas[0].AxisX.IsMarginVisible = false;
            chart1.ChartAreas[0].AxisY.Maximum = 5;
            chart1.ChartAreas[0].AxisY.Minimum = 0;
            chart1.ChartAreas[0].AxisY.Interval = 1;
            chart1.ChartAreas[0].AxisY.MinorTickMark.Enabled = true;
            chart1.ChartAreas[0].AxisY.MinorTickMark.Size = 0.4F;
            chart1.ChartAreas[0].AxisY.MinorTickMark.Interval = 0.5;
            chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Silver;//网格线
            chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Silver;
            chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.True;//曲线无数据时显示XY轴
            chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.True;

            //定义另外3条曲线的ChartArea的属性
            areaSeries1.BackColor = Color.Transparent;
            areaSeries1.BorderColor = Color.Transparent;
            areaSeries1.Position.FromRectangleF(chart1.ChartAreas["ChartArea1"].Position.ToRectangleF());
            areaSeries1.InnerPlotPosition.FromRectangleF(chart1.ChartAreas["ChartArea1"].InnerPlotPosition.ToRectangleF());
            areaSeries1.AxisX.MajorGrid.Enabled = false;//X轴网格，刻度，轴标签
            areaSeries1.AxisX.MajorTickMark.Enabled = false;
            areaSeries1.AxisX.LabelStyle.Enabled = false;
            areaSeries1.AxisX.LineWidth = 0;
            //areaSeries1.AxisX.Enabled = AxisEnabled.False;//将多余Y轴隐藏
            areaSeries1.AxisY.MajorGrid.Enabled = false;//Y轴网格，刻度，标签
            areaSeries1.AxisY.MajorTickMark.Enabled = false;
            areaSeries1.AxisY.LabelStyle.Enabled = false;
            areaSeries1.AxisY.Maximum = 20;
            areaSeries1.AxisY.Minimum = -5;
            areaSeries1.AxisY.Interval = 5;
            areaSeries1.AxisX.Interval = 0.5;
            areaSeries1.AxisX.Minimum = 0;//
            //areaSeries1.AxisX.Maximum = -38.1;
            //areaSeries1.AxisX.Minimum = -40.1;
            //areaSeries1.AxisX.Interval = 0.5;
            // areaSeries1.AxisX.IntervalOffset = 0.1;
            areaSeries1.AxisX.IsMarginVisible = false;
            objSeries2.ChartArea = areaSeries1.Name;

            areaSeries2.BackColor = Color.Transparent;
            areaSeries2.BorderColor = Color.Transparent;
            areaSeries2.Position.FromRectangleF(chart1.ChartAreas["ChartArea1"].Position.ToRectangleF());
            areaSeries2.InnerPlotPosition.FromRectangleF(chart1.ChartAreas["ChartArea1"].InnerPlotPosition.ToRectangleF());
            areaSeries2.AxisX.MajorGrid.Enabled = false;//X轴网格，刻度，轴标签
            areaSeries2.AxisX.MajorTickMark.Enabled = false;
            areaSeries2.AxisX.LabelStyle.Enabled = false;
            areaSeries2.AxisX.LineWidth = 0;
            areaSeries2.AxisY.MajorGrid.Enabled = false;//Y轴网格，刻度，标签
            areaSeries2.AxisY.MajorTickMark.Enabled = false;
            areaSeries2.AxisY.LabelStyle.Enabled = false;
            areaSeries2.AxisY.Maximum = 30;
            areaSeries2.AxisY.Minimum = 0;
            areaSeries2.AxisY.Interval = 5;
            areaSeries2.AxisX.Interval = 1;
            areaSeries2.AxisX.Minimum = 0;
            //areaSeries2.AxisX.Maximum = -38.1;
            //areaSeries2.AxisX.Minimum = -40.1;
            //areaSeries2.AxisX.Interval = 0.5;
            //areaSeries2.AxisX.IntervalOffset = 0.1;
            areaSeries2.AxisX.IsMarginVisible = false;
            objSeries3.ChartArea = areaSeries2.Name;

            areaSeries3.BackColor = Color.Transparent;
            areaSeries3.BorderColor = Color.Transparent;
            areaSeries3.Position.FromRectangleF(chart1.ChartAreas["ChartArea1"].Position.ToRectangleF());
            areaSeries3.InnerPlotPosition.FromRectangleF(chart1.ChartAreas["ChartArea1"].InnerPlotPosition.ToRectangleF());
            areaSeries3.AxisX.MajorGrid.Enabled = false;//X轴网格，刻度，轴标签
            areaSeries3.AxisX.MajorTickMark.Enabled = false;
            areaSeries3.AxisX.LabelStyle.Enabled = false;
            areaSeries3.AxisX.LineWidth = 0;
            areaSeries3.AxisY.MajorGrid.Enabled = false;//Y轴网格，刻度，标签
            areaSeries3.AxisY.MajorTickMark.Enabled = false;
            areaSeries3.AxisY.LabelStyle.Enabled = false;
            areaSeries3.AxisY.Maximum = 10000;
            areaSeries3.AxisY.Minimum = 0;
            areaSeries3.AxisY.Interval = 2000;
            areaSeries3.AxisX.Interval = 0.5;
            areaSeries3.AxisX.Minimum = 0;//
            //areaSeries3.AxisX.Maximum = -38.1;
            //areaSeries3.AxisX.Minimum = -40.1;
            //areaSeries3.AxisX.Interval = 0.5;
            //areaSeries3.AxisX.IntervalOffset = 0.1;
            areaSeries3.AxisX.IsMarginVisible = false;
            objSeries4.ChartArea = areaSeries3.Name;

            areaSeries4.BackColor = Color.Transparent;
            areaSeries4.BorderColor = Color.Transparent;
            areaSeries4.Position.FromRectangleF(chart1.ChartAreas["ChartArea1"].Position.ToRectangleF());
            areaSeries4.InnerPlotPosition.FromRectangleF(chart1.ChartAreas["ChartArea1"].InnerPlotPosition.ToRectangleF());
            areaSeries4.AxisX.MajorGrid.Enabled = false;//X轴网格，刻度，轴标签
            areaSeries4.AxisX.MajorTickMark.Enabled = false;
            areaSeries4.AxisX.LabelStyle.Enabled = false;
            areaSeries4.AxisX.LineWidth = 0;
            areaSeries4.AxisY.Minimum = 0;
            areaSeries4.AxisY.IsStartedFromZero = true;
            areaSeries4.AxisY.MajorGrid.Enabled = false;//Y轴网格，刻度，标签
            areaSeries4.AxisY.MajorTickMark.Enabled = false;
            areaSeries4.AxisY.LabelStyle.Enabled = false;
            areaSeries4.AxisY.Interval = 0.5;
            areaSeries4.AxisX.Minimum = 0;//
            //areaSeries4.AxisX.Interval = 400;
            areaSeries4.AxisX.IsMarginVisible = false;
            objSeries5.ChartArea = areaSeries4.Name;

            //定义新增Y轴的ChartArea属性
            areaAxis1.BackColor = Color.Transparent;
            areaAxis1.BorderColor = Color.Transparent;
            areaAxis1.Position.FromRectangleF(chart1.ChartAreas["ChartArea1"].Position.ToRectangleF());
            areaAxis1.InnerPlotPosition.FromRectangleF(chart1.ChartAreas["ChartArea1"].InnerPlotPosition.ToRectangleF());
            areaAxis1.Position.X -= 5;
            areaAxis1.AxisX.Minimum = 0;//
            areaAxis1.AxisX.LineWidth = 0;
            areaAxis1.AxisX.MajorGrid.Enabled = false;
            areaAxis1.AxisX.MajorTickMark.Enabled = false;
            areaAxis1.AxisX.LabelStyle.Enabled = false;
            areaAxis1.AxisY.MajorGrid.Enabled = false;
            areaAxis1.AxisY.MajorTickMark.Enabled = true;//多Y轴的刻度线
            areaAxis1.AxisY.Enabled = AxisEnabled.True;
            areaAxis1.AxisY.LineColor = chart1.Series["扭矩"].Color;//Y轴颜色
            areaAxis1.AxisY.MajorTickMark.LineColor = chart1.Series["扭矩"].Color;
            areaAxis1.AxisY.MinorTickMark.LineColor = chart1.Series["扭矩"].Color;
            areaAxis1.AxisY.Maximum = 20;
            areaAxis1.AxisY.Minimum = -5;
            areaAxis1.AxisY.Interval = 5;
            areaAxis1.AxisY.MinorTickMark.Enabled = true;
            areaAxis1.AxisY.MinorTickMark.Size = 0.4F;
            areaAxis1.AxisY.MinorTickMark.Interval = 2.5;

            areaAxis2.BackColor = Color.Transparent;
            areaAxis2.BorderColor = Color.Transparent;
            areaAxis2.Position.FromRectangleF(chart1.ChartAreas["ChartArea1"].Position.ToRectangleF());
            areaAxis2.InnerPlotPosition.FromRectangleF(chart1.ChartAreas["ChartArea1"].InnerPlotPosition.ToRectangleF());
            areaAxis2.Position.X -= 10;
            areaAxis2.AxisX.Minimum = 0;//
            areaAxis2.AxisX.LineWidth = 0;
            areaAxis2.AxisX.MajorGrid.Enabled = false;
            areaAxis2.AxisX.MajorTickMark.Enabled = false;
            areaAxis2.AxisX.LabelStyle.Enabled = false;
            areaAxis2.AxisY.MajorGrid.Enabled = false;
            areaAxis2.AxisY.MajorTickMark.Enabled = true;//多Y轴的刻度线
            areaAxis2.AxisY.Enabled = AxisEnabled.True;
            areaAxis2.AxisY.LineColor = chart1.Series["进给速度"].Color;//Y轴颜色
            areaAxis2.AxisY.MajorTickMark.LineColor = chart1.Series["进给速度"].Color;
            areaAxis2.AxisY.MinorTickMark.LineColor = chart1.Series["进给速度"].Color;
            areaAxis2.AxisY.Maximum = 30;
            areaAxis2.AxisY.Minimum = 0;
            areaAxis2.AxisY.Interval = 5;
            areaAxis2.AxisY.MinorTickMark.Enabled = true;
            areaAxis2.AxisY.MinorTickMark.Size = 0.4F;
            areaAxis2.AxisY.MinorTickMark.Interval = 1;

            areaAxis3.BackColor = Color.Transparent;
            areaAxis3.BorderColor = Color.Transparent;
            areaAxis3.Position.FromRectangleF(chart1.ChartAreas["ChartArea1"].Position.ToRectangleF());
            areaAxis3.InnerPlotPosition.FromRectangleF(chart1.ChartAreas["ChartArea1"].InnerPlotPosition.ToRectangleF());
            areaAxis3.Position.X -= 15;
            areaAxis3.AxisX.Minimum = 0;//
            areaAxis3.AxisX.LineWidth = 0;
            areaAxis3.AxisX.MajorGrid.Enabled = false;
            areaAxis3.AxisX.MajorTickMark.Enabled = false;
            areaAxis3.AxisX.LabelStyle.Enabled = false;
            areaAxis3.AxisY.MajorGrid.Enabled = false;
            areaAxis3.AxisY.MajorTickMark.Enabled = true;//多Y轴的刻度线
            areaAxis3.AxisY.Enabled = AxisEnabled.True;
            areaAxis3.AxisY.LineColor = chart1.Series["旋转速度"].Color;//Y轴颜色
            areaAxis3.AxisY.MajorTickMark.LineColor = chart1.Series["旋转速度"].Color;
            areaAxis3.AxisY.MinorTickMark.LineColor = chart1.Series["旋转速度"].Color;
            areaAxis3.AxisY.Maximum = 10000;
            areaAxis3.AxisY.Minimum = 0;
            areaAxis3.AxisY.Interval = 2000;
            areaAxis3.AxisY.MinorTickMark.Enabled = true;
            areaAxis3.AxisY.MinorTickMark.Size = 0.4F;
            areaAxis3.AxisY.MinorTickMark.Interval = 500;
            areaAxis3.AxisY.LabelStyle.Angle = 0;

            areaAxis4.BackColor = Color.Transparent;
            areaAxis4.BorderColor = Color.Transparent;
            areaAxis4.Position.FromRectangleF(chart1.ChartAreas["ChartArea1"].Position.ToRectangleF());
            areaAxis4.InnerPlotPosition.FromRectangleF(chart1.ChartAreas["ChartArea1"].InnerPlotPosition.ToRectangleF());
            areaAxis4.Position.X -= 20;
            areaAxis4.AxisX.Minimum = 0;//
            areaAxis4.AxisX.LineWidth = 0;
            areaAxis4.AxisX.MajorGrid.Enabled = false;
            areaAxis4.AxisX.MajorTickMark.Enabled = false;
            areaAxis4.AxisX.LabelStyle.Enabled = false;
            areaAxis4.AxisY.Minimum = 0;
            areaAxis4.AxisY.IsStartedFromZero = true;
            areaAxis4.AxisY.MajorGrid.Enabled = false;
            areaAxis4.AxisY.MajorTickMark.Enabled = false;//多Y轴的刻度线
            areaAxis4.AxisY.Enabled = AxisEnabled.False;
            areaAxis4.AxisY.LineColor = chart1.Series["进给位移"].Color;//Y轴颜色
            areaAxis4.AxisY.MajorTickMark.LineColor = chart1.Series["进给位移"].Color;
            areaAxis4.AxisY.MinorTickMark.LineColor = chart1.Series["进给位移"].Color;
            areaAxis4.AxisY.Interval = 0.5;
            areaAxis4.AxisY.MinorTickMark.Enabled = true;
            areaAxis4.AxisY.MinorTickMark.Interval = 0.25;
            areaAxis4.AxisY.LabelStyle.Angle = 0;

            // Hide copied series
            seriesCopy1.IsVisibleInLegend = false;//不在图例中显示该曲线图例
            seriesCopy1.Color = Color.Transparent;
            seriesCopy1.BorderColor = Color.Transparent;
            seriesCopy1.ChartArea = areaAxis1.Name;
            seriesCopy2.IsVisibleInLegend = false;//不在图例中显示该曲线图例
            seriesCopy2.Color = Color.Transparent;
            seriesCopy2.BorderColor = Color.Transparent;
            seriesCopy2.ChartArea = areaAxis2.Name;
            seriesCopy3.IsVisibleInLegend = false;//不在图例中显示该曲线图例
            seriesCopy3.Color = Color.Transparent;
            seriesCopy3.BorderColor = Color.Transparent;
            seriesCopy3.ChartArea = areaAxis3.Name;
            seriesCopy4.IsVisibleInLegend = false;//不在图例中显示该曲线图例
            seriesCopy4.Color = Color.Transparent;
            seriesCopy4.BorderColor = Color.Transparent;
            seriesCopy4.ChartArea = areaAxis4.Name;

            objSeries5.IsVisibleInLegend = false;//不在图例中显示该曲线图例

            foreach (Series item in this.chart1.Series)
            {
                item.ChartType = SeriesChartType.Line;//样条图和折线图
                item.BorderWidth = 1;//曲线粗细程度
                item.Points.AddXY(0, 0);
            }

            //chart1.Series["压力"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY1);
            //chart1.Series["扭矩"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY2);
            //chart1.Series["进给速度"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY3);
            //chart1.Series["旋转速度"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY4);
            //foreach (DataPoint point in chart1.Series["扭矩"].Points)
            //{
            //    chart1.Series["扭矩_Copy"].Points.AddXY(point.XValue, point.YValues[0]);
            //}
            //foreach (DataPoint point in chart1.Series["进给速度"].Points)
            //{
            //    chart1.Series["进给速度_Copy"].Points.AddXY(point.XValue, point.YValues[0]);
            //}
            //foreach (DataPoint point in chart1.Series["旋转速度"].Points)
            //{
            //    chart1.Series["旋转速度_Copy"].Points.AddXY(point.XValue, point.YValues[0]);
            //}
            #endregion

            //初始化CheckBox,向曲线集合内赋值
            this.Chk_DataPressure.Checked = true;
            this.Chk_DataTorque.Checked = true;
            this.Chk_ActVelo1.Checked = true;
            this.Chk_ActVelo2.Checked = true;
            this.Chk_ActPos.Checked = false;
            this.label5.Visible = false;

            this.lbl_UpdateTime.Text = CommonMethods.objReport.UpdateTime.ToString();
            this.lbl_SettingsName.Text = CommonMethods.objReport.SettingsName;
        }

        #region CheckBox显示隐藏曲线
        private void Chk_DataPressure_CheckedChanged(object sender, EventArgs e)
        {
            chart1.Series["压力"].Points.Clear();
            if (Chk_DataPressure.Checked)
            {
                chart1.Series["压力"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY1);
                chart1.Series["压力"].Color = Color.Black;//显示
                chart1.Series["压力"].IsVisibleInLegend = true;
            }
            else
            {
                chart1.Series["压力"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY1);
                chart1.Series["压力"].Color = Color.Transparent;//不显示
                chart1.Series["压力"].IsVisibleInLegend = false;//不在图例中显示该曲线图例
            }
        }

        private void Chk_DataTorque_CheckedChanged(object sender, EventArgs e)
        {
            chart1.Series["扭矩"].Points.Clear();
            chart1.Series["扭矩_Copy"].Points.Clear();
            if (Chk_DataTorque.Checked)
            {
                chart1.Series["扭矩"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY2);
                chart1.Series["扭矩"].IsVisibleInLegend = true;
                foreach (DataPoint point in chart1.Series["扭矩"].Points)
                {
                    chart1.Series["扭矩_Copy"].Points.AddXY(point.XValue, point.YValues[0]);
                }
            }
            else
            {
                chart1.Series["扭矩"].Points.AddXY(0, 0);
                chart1.Series["扭矩_Copy"].Points.AddXY(0, 0);
                chart1.Series["扭矩"].IsVisibleInLegend = false;
            }
        }

        private void Chk_ActVelo1_CheckedChanged(object sender, EventArgs e)
        {
            chart1.Series["进给速度"].Points.Clear();
            chart1.Series["进给速度_Copy"].Points.Clear();
            if (Chk_ActVelo1.Checked)
            {
                chart1.Series["进给速度"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY3);
                chart1.Series["进给速度"].IsVisibleInLegend = true;
                foreach (DataPoint point in chart1.Series["进给速度"].Points)
                {
                    chart1.Series["进给速度_Copy"].Points.AddXY(point.XValue, point.YValues[0]);
                }
            }
            else
            {
                chart1.Series["进给速度"].Points.AddXY(0, 0);
                chart1.Series["进给速度_Copy"].Points.AddXY(0, 0);
                chart1.Series["进给速度"].IsVisibleInLegend = false;//不在图例中显示该曲线图例
            }
        }

        private void Chk_ActVelo2_CheckedChanged(object sender, EventArgs e)
        {
            chart1.Series["旋转速度"].Points.Clear();
            chart1.Series["旋转速度_Copy"].Points.Clear();
            if (Chk_ActVelo2.Checked)
            {
                chart1.Series["旋转速度"].Points.DataBindXY(Beckhoff_PLC.AX, Beckhoff_PLC.AY4);
                chart1.Series["旋转速度"].IsVisibleInLegend = true;
                foreach (DataPoint point in chart1.Series["旋转速度"].Points)
                {
                    chart1.Series["旋转速度_Copy"].Points.AddXY(point.XValue, point.YValues[0]);
                }
            }
            else
            {
                chart1.Series["旋转速度"].Points.AddXY(0, 0);
                chart1.Series["旋转速度_Copy"].Points.AddXY(0, 0);
                chart1.Series["旋转速度"].IsVisibleInLegend = false;//不在图例中显示该曲线图例
            }
        }
        #endregion

        private void Chk_ActPos_CheckedChanged(object sender, EventArgs e)
        {
            //chart1.Series["进给位移"].Points.Clear();
            //chart1.Series["进给位移_Copy"].Points.Clear();
            //if (Chk_ActPos.Checked)
            //{
            //    chart1.Series["进给位移"].Points.DataBindXY(Beckhoff_PLC.AX1, Beckhoff_PLC.AX2);
            //    chart1.Series["进给位移"].IsVisibleInLegend = true;
            //    foreach (DataPoint point in chart1.Series["进给位移"].Points)
            //    {
            //        chart1.Series["进给位移_Copy"].Points.AddXY(point.XValue, point.YValues[0]);
            //    }
            //}
            //else
            //{
            //    chart1.Series["进给位移"].Points.AddXY(0, 0);
            //    chart1.Series["进给位移_Copy"].Points.AddXY(0, 0);
            //    chart1.Series["进给位移"].IsVisibleInLegend = false;//不在图例中显示该曲线图例
            //}
            if (Chk_ActPos.Checked)//选中
            {
                Beckhoff_PLC.AX.Clear();
                foreach (float item in Beckhoff_PLC.AX1)
                {
                    Beckhoff_PLC.AX.Add(item);
                }
                chart1.Series["进给位移"].Points.Clear();
                chart1.Series["进给位移_Copy"].Points.Clear();
                chart1.Series["进给位移"].Points.DataBindXY(Beckhoff_PLC.AX1, Beckhoff_PLC.AX2);
                foreach (DataPoint point in chart1.Series["进给位移"].Points)
                {
                    chart1.Series["进给位移_Copy"].Points.AddXY(point.XValue, point.YValues[0]);
                }

                chart1.Series["进给位移"].IsVisibleInLegend = true;//在图例中显示该曲线图例                
                chart1.ChartAreas[0].AxisX.Title = "时间(ms)";

                chart1.ChartAreas[0].AxisX.Interval = 400;
                chart1.ChartAreas[0].AxisX.IsMarginVisible = false;

                chart1.ChartAreas["ChartArea2"].AxisX.Interval = 400;
                chart1.ChartAreas["ChartArea4"].AxisX.Interval = 400;
                chart1.ChartAreas["ChartArea6"].AxisX.Interval = 400;
                chart1.ChartAreas["ChartArea8"].AxisX.Interval = 400;
                chart1.ChartAreas["ChartArea9"].AxisY.MajorTickMark.Enabled = true;//多Y轴的刻度线
                chart1.ChartAreas["ChartArea9"].AxisY.Enabled = AxisEnabled.True;

                this.label5.Visible = true;

                this.Chk_DataPressure_CheckedChanged(null, null);
                this.Chk_DataTorque_CheckedChanged(null, null);
                this.Chk_ActVelo1_CheckedChanged(null, null);
                this.Chk_ActVelo2_CheckedChanged(null, null);
            }
            else
            {
                Beckhoff_PLC.AX.Clear();
                foreach (float item in Beckhoff_PLC.AX2)
                {
                    Beckhoff_PLC.AX.Add(item);
                }
                chart1.Series["进给位移"].Points.Clear();
                chart1.Series["进给位移"].IsVisibleInLegend = false;//不在图例中显示该曲线图例
                chart1.ChartAreas[0].AxisX.Title = "进给位移(mm)";

                chart1.ChartAreas[0].AxisX.Interval = 0.5;
                chart1.ChartAreas[0].AxisX.IsMarginVisible = false;
                chart1.ChartAreas["ChartArea2"].AxisX.Interval = 0.5;
                chart1.ChartAreas["ChartArea4"].AxisX.Interval = 0.5;
                chart1.ChartAreas["ChartArea6"].AxisX.Interval = 0.5;
                chart1.ChartAreas["ChartArea8"].AxisX.Interval = 0.5;

                chart1.ChartAreas["ChartArea9"].AxisY.MajorTickMark.Enabled = false;//多Y轴的刻度线
                chart1.ChartAreas["ChartArea9"].AxisY.Enabled = AxisEnabled.False;

                this.label5.Visible = false;

                this.Chk_DataPressure_CheckedChanged(null, null);
                this.Chk_DataTorque_CheckedChanged(null, null);
                this.Chk_ActVelo1_CheckedChanged(null, null);
                this.Chk_ActVelo2_CheckedChanged(null, null);
            }
        }

        private void TopPanel_Paint(object sender, PaintEventArgs e)
        {

        }

        private void LeftPanel_Paint(object sender, PaintEventArgs e)
        {

        }
   
        private void chart1_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                var area = chart1.ChartAreas[0];
                var area1 = chart1.ChartAreas[1];
                var area2 = chart1.ChartAreas[2];
                var area3 = chart1.ChartAreas[3];
                var area8 = chart1.ChartAreas[8];
                //var area5 = chart1.ChartAreas[5];

                //double xValue = area.AxisX.PixelPositionToValue(e.X);
                double yValue = area.AxisY.PixelPositionToValue(e.Y);
                double yValue1 = area1.AxisY.PixelPositionToValue(e.Y);
                double yValue2 = area2.AxisY.PixelPositionToValue(e.Y);
                double yValue3 = area3.AxisY.PixelPositionToValue(e.Y);
                double yValue8 = area8.AxisY.PixelPositionToValue(e.Y);
                //double yValue5 = area5.AxisY.PixelPositionToValue(e.Y);
                if (Chk_ActPos.Checked)//选中
                {
                    tt.SetToolTip(chart1, "压力:" + yValue.ToString("F2") + "\r" +
                                      "扭矩:" + yValue1.ToString("F2") + "\r" +
                                      "进给速度:" + yValue2.ToString("F2") + "\r" +
                                      "旋转速度:" + yValue3.ToString("F2") + "\r" +
                                      "进给位移:" + yValue8.ToString("F2") + " "
                                      );
                }
                else
                {

                    tt.SetToolTip(chart1, "压力:" + yValue.ToString("F2") + "\r" +
                    "扭矩:" + yValue1.ToString("F2") + "\r" +
                    "进给速度:" + yValue2.ToString("F2") + "\r" +
                    "旋转速度:" + yValue3.ToString("F2") + " "  
                    );

                }
            }
            catch
            {

            }



        }
    }
}
